package org.teacup.eightdays.mobileserver.controller;

import java.io.Serializable;

import javacommon.base.BaseSpringController;

import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * 手机服务端Controller基类<br>
 * 编写手机服务时，请继承此类.<br>
 * 并在返回结果前，调用{@link BaseMobileServerConntroller#getModelAndView(Serializable)}
 * 方法获取返回结果
 * 
 * <pre>
 * 示例:
 * <code>
 * (a)Controller
 * public class XXController extends BaseMobileServerConntroller{
 * 		// 此处的方法参数，请根据自身实际情况定义。
 * 		public ModelAndView show(HttpServletRequest request,HttpServletResponse response) throws Exception {
 * 			// 类型不限，实现java.io.Serializable 即可
 * 			Serializable obj  ;
 * 			// List<Object> obj;
 * 			// some codes..
 * 			return super.getModelAndView(obj); 
 * 		}
 * }
 * </code>
 * </pre>
 * 
 * @author Abner
 */
public class BaseMobileServerConntroller extends BaseSpringController {
	private final static String VIEW_NAME = "/mobile/result";

	/**
	 * @param obj
	 */
	public ModelAndView getModelAndView(Serializable obj) {
		ModelAndView mav = new ModelAndView(VIEW_NAME);
		mav.addObject("result", JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat));
		return mav;
	}

}
